<?php

namespace app\home\controller;

use app\home\lib\MyController;
use think\Db;

class Login extends MyController
{
	// https://jiankangpao.sichuancancer.org/azfzjkp_dev/home/login/phpinfo.html
	public function phpinfo()
	{
		echo phpinfo();
		die();
	}

	// 登录 admin azfzjkp
	// http://192.168.8.130/azfzjkp_dev/home/login/login.html
	// https://jiankangpao.sichuancancer.org/azfzjkp_dev/home/login/login.html
	public function login()
	{
		$this->assign('name', "肿瘤防治健康跑");
		$this->assign('time', date('Y'));
		return $this->fetch();
	}

	public function do_login()
	{
		session(null);
		session('NOW_ENV', NOW_ENV);

		$name = input('name');
		$pass = input('pass');

		if (empty($name) || empty($pass)) {
			$this->error('用户名或密码为空！');
		}

		$tmp_where['name'] = $name;
		$tmp_where['password'] = $pass;
		$res = db('account')->where($tmp_where)->find();
		if ($res) {
			session("admin_login_status", 'OK');
			session('user_id', $res['id']);
			session('user_name', $name);
			session('user_class', $res['class']);

			$this->redirect('Qa/recordList', array(), 1, '登录成功...');
		} else {
			$this->error('用户名或密码错误！');
		}
	}

	// 退出
	public function logout()
	{
		session(null);
		$this->redirect('login/login', array(), 1, '退出成功...');
	}
}
